package com.iceland.common.rpc;

import com.iceland.common.util.ClassUtil;

import java.util.LinkedList;
import java.util.List;

public class RemoteServiceScanner {

    private static List<Class> interfaceClass=new LinkedList<>();
    private static List<Class> instanceClass=new LinkedList<>();
    public static  List<Class> scan(String packageName){
        if(packageName==null){
            packageName="";
        }
        List<Class> allClassByAnnotation = ClassUtil.getAllClassByAnnotation(RemoteService.class, packageName);
        allClassByAnnotation.forEach(aClass -> {
            if(aClass.isInterface()){
                interfaceClass.add(aClass);
            }
            else {
                instanceClass.add(aClass);
            }
        });
        return allClassByAnnotation;
    }

    public static List<Class> getInterfaceClass() {
        return interfaceClass;
    }

    public static void setInterfaceClass(List<Class> interfaceClass) {
        RemoteServiceScanner.interfaceClass = interfaceClass;
    }

    public static List<Class> getInstanceClass() {
        return instanceClass;
    }

    public static void setInstanceClass(List<Class> instanceClass) {
        RemoteServiceScanner.instanceClass = instanceClass;
    }
}
